import Vue from 'vue'
import storage from 'store'
import {
  APP_USER
} from '@/store/mutation-types'

import {
  ACCEPT_ASSIGN, HEAR_ASSIGN
} from '@/utils/custom/custom-role.js'
import {
  Tp_categoryValue
} from '@/enumeration/Tp_category.js'

/**
 * 行政复议-受理-录入人员, 分派权限控制
 */
const A_assign = Vue.directive('A_assign', {
  inserted: function (el, binding, vnode) {
    if (binding.value != Tp_categoryValue.accept) {
      el.parentNode && el.parentNode.removeChild(el) || (el.style.display = 'none')
      return
    }
    const currentUser = storage.get(APP_USER)
    let isassign = false
    // 行政复议-受理-录入人员, 分派权限控制
    if (currentUser.roles) {
      currentUser.roles.forEach((id) => {
        if (ACCEPT_ASSIGN.includes(id)) {
          isassign = true
        }
      })
    }
    if (!isassign) {
      el.parentNode && el.parentNode.removeChild(el) || (el.style.display = 'none')
    }
    return
  }
})

/**
 * 行政复议-审理-录入人员, 分派权限控制
 */
const H_assign = Vue.directive('H_assign', {
  inserted: function (el, binding, vnode) {
    if (binding.value != Tp_categoryValue.hear) {
      el.parentNode && el.parentNode.removeChild(el) || (el.style.display = 'none')
      return
    }
    const currentUser = storage.get(APP_USER)
    let isassign = false
    // 行政复议-审理-录入人员, 分派权限控制
    if (currentUser.roles) {
      currentUser.roles.forEach((id) => {
        if (HEAR_ASSIGN.includes(id)) {
          isassign = true
        }
      })
    }
    if (!isassign) {
      el.parentNode && el.parentNode.removeChild(el) || (el.style.display = 'none')
    }
    return
  }
})


export default {
  A_assign,
  H_assign
}